﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;

namespace aboveXWords.GUI
{
  [Serializable]
  public class HandleCollection : List<Handle>
  {
    [NonSerialized] private GraphicsPath m_path;

    public Handle Moving { get; set; }

    internal void CreateGraphics()
    {
      m_path = new GraphicsPath();
      foreach (Handle handle in this)
        handle.Create(m_path);
    }

    public void Paint(Graphics graphics)
    {
      CreateGraphics();
      graphics.FillPath(new SolidBrush(Color.White), m_path);
      graphics.DrawPath(new Pen(Color.Black), m_path);
    }

    internal Handle Hit(PointF mousePosition)
    {
      return this.Where(t => t.Contains(mousePosition)).FirstOrDefault();
    }

    internal void Move(float x, float y)
    {
      foreach (Handle handle in this)
        handle.PointF = new PointF(handle.PointF.X + x, handle.PointF.Y + y);
    }
  }
}